#ifndef __TCP_CONN_H__
#define __TCP_CONN_H__

#include <stdint.h>
#include <netinet/in.h>
#include <liburing.h>

typedef enum tagTcpConnEvent
{
    TCP_CONN_ACCEPT,
    TCP_CONN_READ,
    TCP_CONN_WRITE,
}TCP_CONN_EVENT_E;


typedef struct tagTcpUserData
{
    union {
		struct {
			// uint16_t op_tid; /* 4 bits op, 12 bits tid */
			// uint16_t bid;
			// uint16_t fd;

            uint32_t          uiConnId;
            TCP_CONN_EVENT_E  enEvent;
		};
		uint64_t ui64Value;
	};
}TCP_USER_DATA_S;

typedef struct TCPConnection
{
    uint32_t uiConnId;
    int32_t  iFd;
    union {
		struct sockaddr_in stLocalAddr;
		struct sockaddr_in6 stLocalAddr6;
	};

    socklen_t ulAddrLen;

    union {
		struct sockaddr_in stPeerAddr;
		struct sockaddr_in6 stPeerAddr6;
	};

    char acBuf[8192];
    char* pcBuf;
    size_t ulBufLen;
    size_t ulDataLen;
}TCP_CONNECTION_S;

TCP_CONNECTION_S* TCP_conn_CreateListener(const char* pcHostName, uint16_t usPort);

int TCP_conn_Handle(struct io_uring_cqe* pstCQE);

#endif //__TCP_CONN_H__